package com.oros.db;

import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import java.io.Serializable;
import java.util.HashSet;

public class AEInFilter implements Filter,Serializable {
	private static final long serialVersionUID = -5579490577623796943L;
    public String columnName;
    public HashSet<?> origin;
    int hashcode;
	public AEInFilter(String columnName,HashSet<?> origin)
	{
		this.columnName = columnName;
		this.origin = origin;
		hashcode = columnName.hashCode() ^ 19701976;
		if (origin!=null) hashcode ^=20042006;
	}
	@Override
	public boolean passesFilter(Object itemId, Item item)
			throws UnsupportedOperationException {
		if (origin==null) return true;
		final Property p = item.getItemProperty(columnName);
		        if (null == p) {
		            return false;
		        }
		Object value = p.getValue();
		if (value==null) return false;
		return origin.contains(value);
	}

	@Override
	public boolean appliesToProperty(Object propertyId) {
		return columnName.equals(propertyId);
	}
	@Override
    public boolean equals(Object obj) {
	        // Only objects of the same class can be equal
	        if (!getClass().equals(obj.getClass())) {
	            return false;
	        }
	        AEInFilter filt=(AEInFilter)obj;
	        if (!columnName.equals(filt.columnName)) return false;
	        if (origin==null && filt.origin==null) return true;
	        if (origin==null || filt.origin==null || !origin.equals(filt.origin))
	        	return false;
	        return true;
	}
	 @Override
     public int hashCode() { return hashcode; }
}
